import {getAnnouncementTitleList} from "../../api/Infomange"
import {onMounted,reactive,ref} from "vue"
import {useStore} from "vuex"
export function useAnnouncementTitleList(){
	const {state} = useStore()
	const DATA = ref<any>([])
	const COUNTNUM = ref<number>(0)
	function initAnnouncementTitleList(params:{
		XX_BT:string
		Page:string
		PageSize:string
	}){
		return new Promise((resolve,reject)=>{
			getAnnouncementTitleList({
				XX_BT:params?.XX_BT || "",
				PAGEINDEX:params?.Page  || "1",
				PAGESIZE:params?.PageSize || "10",
				OPERATOR_ID: state.user.userInfo.CUSER_ID || "0"
			})
			.then(res=>{
				if (res.ERROR[0].errcode == '0'){
					DATA.value = res.DAT
					COUNTNUM.value = parseInt(String(res.COUNT[0].NUM / 10)) + (res.COUNT[0].NUM % 10 === 0 ? 0 : 1)
				    resolve(res)
				}else {
				    uni.showToast({
				        title: res.ERROR[0].error,
				        icon: 'none',
				        mask: true
				    })
				    reject('err')
				}
			})
			.catch(err=>{
				uni.showToast({
				    title: '获取列表失败',
				    icon: 'error',
				    mask: true
				})
				reject('err')
			})
		})
	}
	return {
		initAnnouncementTitleList,
		DATA,
		COUNTNUM
	}
}